package utils

import (
	"fmt"
	"github.com/shirou/gopsutil/host"
	"github.com/shirou/gopsutil/mem"
	"runtime"
)

func GetOSInfo() string {
	return runtime.GOOS
}

// 开机时间
func GetUpTime() string {
	u, e := host.Uptime()
	if e != nil {
		return ""
	}
	return FormatDuring(int64(u * 1000))
}

// CPU信息
func GetCpuInfo() string {
	return fmt.Sprintf("%s/%d核", runtime.GOARCH, runtime.NumCPU())
}

// 内存总量
func TotalMemory() uint64 {
	v, err := mem.VirtualMemory()
	if err == nil {
		return v.Total
	}
	return 0
}

// 内存空闲
func FreeMemory() uint64 {
	v, err := mem.VirtualMemory()
	if err == nil {
		return v.Total - v.Used
	}
	return 0
}
